package com.mdlib.helper.ui.adapter;

import android.content.Context;
import android.os.Environment;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.ljlib.help.R;
import com.mdlib.helper.utils.GlideRoundTransform;

import java.io.File;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.finalteam.galleryfinal.model.PhotoInfo;

/**
 * 作者：HQY on 16/12/13 17:31
 * 邮箱：hqy_xz@126.com
 */

public class MinnOrTakeAdapter extends RecyclerView.Adapter<MinnOrTakeAdapter.ViewHolder> {

    private List<PhotoInfo> mList;
    private Context mContext;

    public MinnOrTakeAdapter(List<PhotoInfo> list, Context context) {
        this.mList = list;
        this.mContext = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_order_goods_pic, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        PhotoInfo photoInfo = mList.get(position);
        Glide.with(mContext)//new File(photoInfo.getPhotoPath())
                .load(new File(photoInfo.getPhotoPath()))
                .transform(new GlideRoundTransform(mContext, 5))
                .into(holder.mIvOrderPic);
    }

    //  删除指定的Item
    public int removeData(int position) {
        mList.remove(position);
        //  通知RecyclerView控件某个Item已经被删除
        notifyItemRemoved(position);

        return mList.size();
    }

    //  在指定位置添加一个新的Item
    public void addItem(List<PhotoInfo> person) {
        for (int i = 0; i < person.size(); i++) {
            mList.add(person.get(i));
            //  通知RecyclerView控件插入了某个Item
            notifyItemInserted(mList.size());
        }
    }

    public List<PhotoInfo> getList() {
        return mList;
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        @Bind(R.id.iv_order_pic)
        ImageView mIvOrderPic;
        @Bind(R.id.iv_order_pic_delete)
        ImageView mIvOrderPicDelete;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);

        }
    }

    //    public MinnOrTakeAdapter(List<PhotoInfo> data) {
//        super(R.layout.item_order_goods_pic, data);
//    }
//
//    @Override
//    protected void convert(BaseViewHolder baseViewHolder, PhotoInfo photoInfo) {
//        baseViewHolder.addOnClickListener(R.id.iv_order_pic_delete);
//        Glide.with(mContext)
//                .load(new File(photoInfo.getPhotoPath()))
//                .into((ImageView) baseViewHolder.getView(R.id.iv_order_pic));
//    }
}
